/*    */ package cc.s2m.web.s2mBlog.controller.admin;
/*    */ 
/*    */ import cc.s2m.util.CookieUtil;
/*    */ import cc.s2m.util.IpUtil;
/*    */ import cc.s2m.web.s2mBlog.controller.base.BaseController;
/*    */ import cc.s2m.web.s2mBlog.pojo.Admin;
/*    */ import cc.s2m.web.s2mBlog.service.IAdmin;
/*    */ import cc.s2m.web.s2mBlog.util.MemcacheKeys;
/*    */ import cc.s2m.web.s2mBlog.util.StaticProp;
/*    */ import java.util.Date;
/*    */ import javax.servlet.http.HttpServletRequest;
/*    */ import javax.servlet.http.HttpServletResponse;
/*    */ import javax.servlet.http.HttpSession;
/*    */ import net.spy.memcached.MemcachedClient;
/*    */ import org.apache.commons.codec.digest.DigestUtils;
/*    */ import org.springframework.beans.factory.annotation.Autowired;
/*    */ import org.springframework.stereotype.Controller;
/*    */ import org.springframework.web.bind.annotation.RequestMapping;
/*    */ import org.springframework.web.bind.annotation.RequestParam;
/*    */ import org.springframework.web.bind.annotation.ResponseBody;
/*    */ 
/*    */ @Controller("admin_login")
/*    */ @RequestMapping({"/admin"})
/*    */ public class Login extends BaseController
/*    */ {
/*    */ 
/*    */   @Autowired
/*    */   private MemcachedClient memcachedClient;
/*    */ 
/*    */   @Autowired
/*    */   private IAdmin adminService;
/*    */ 
/*    */   @RequestMapping(value={"/login"}, method={org.springframework.web.bind.annotation.RequestMethod.GET})
/*    */   public String login()
/*    */   {
/* 37 */     return "admin/login";
/*    */   }
/*    */ 
/*    */   @RequestMapping(value={"/login/check"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
/*    */   @ResponseBody
/*    */   public String check(HttpServletRequest request, HttpServletResponse response, @RequestParam String username, @RequestParam String password, @RequestParam String picCode)
/*    */   {
/* 47 */     if (!checkCodeIsEqual(request, picCode)) {
/* 48 */       return "errorPicCode";
/*    */     }
/* 50 */     Admin condition = new Admin();
/* 51 */     condition.setUsername(username);
/* 52 */     Admin admin = (Admin)this.adminService.getByCondition(condition);
/* 53 */     if (admin == null) {
/* 54 */       return "noRecord";
/*    */     }
/* 56 */     if (!admin.getPwd().equals(DigestUtils.md5Hex(password))) {
/* 57 */       return "errorPassword";
/*    */     }
/* 59 */     if (admin.getIsLock().booleanValue()) {
/* 60 */       return "isLock";
/*    */     }
/* 62 */     CookieUtil cookie = new CookieUtil(request, response);
/* 63 */     String cookieId = request.getSession(true).getId();
/* 64 */     cookie.setCookie(StaticProp.cookieID, cookieId, Integer.valueOf(-1), null);
/* 65 */     this.memcachedClient.set(MemcacheKeys.ADMIN_SESSION.getKey() + cookieId, 1800, admin);
/*    */ 
/* 67 */     admin.setDateLogin(new Date());
/* 68 */     admin.setIpLogin(IpUtil.getIp(request));
/* 69 */     this.adminService.updateByPrimaryKey(admin);
/* 70 */     return "success";
/*    */   }
/*    */ 
/*    */   @RequestMapping(value={"/loginout"}, method={org.springframework.web.bind.annotation.RequestMethod.GET})
/*    */   public String out(HttpServletRequest request, HttpServletResponse response)
/*    */   {
/* 84 */     CookieUtil cookie = new CookieUtil(request, response);
/* 85 */     String cookieId = cookie.getCookie(StaticProp.cookieID);
/* 86 */     if ((cookieId != null) && (!cookieId.trim().isEmpty())) {
/* 87 */       this.memcachedClient.delete(MemcacheKeys.ADMIN_SESSION.getKey() + cookieId);
/* 88 */       cookie.removeCookie(StaticProp.cookieID, null);
/*    */     }
/* 90 */     return "redirect:/admin/login";
/*    */   }
/*    */ }

/* Location:           C:\Users\Administrator\Desktop\s2mBlog.zip
 * Qualified Name:     s2mBlog-3.0.0.WEB-INF.classes.cc.s2m.web.s2mBlog.controller.admin.Login
 * JD-Core Version:    0.6.1
 */